<?php


namespace app\admin\controller\setting;

use app\admin\controller\AdminController;
use app\admin\service\setting\AreaService;
use app\admin\validate\setting\AreaValidate;
use think\response\Json;

/*
 * 区域控制器
 */
class Area extends AdminController
{
    /**
     * 获取区域列表
     * @return Json
     */
    public function lists()
    {
        return $this->success(AreaService::lists($this->paramData(['code'])));
    }

    /**
     * 添加区域
     * @return Json
     */
    public function add()
    {
        $params = (new AreaValidate())->post()->checkParam('add');
        $result =  AreaService::add($params);
        if(true === $result) {
            return $this->success([], '添加成功');
        } else {
            return $this->error(AreaService::getError());
        }
    }

    /**
     * 编辑区域
     * @return Json
     */
    public function edit()
    {
        $params = (new AreaValidate())->post()->checkParam('edit');
        $result = AreaService::edit($params);
        if(true === $result) {
            return $this->success([], '编辑成功');
        } else {
            return $this->error(AreaService::getError());
        }
    }

    /**
     * 删除区域
     * @return Json
     */
    public function delete()
    {
        $params = (new AreaValidate())->delete()->checkParam('delete');
        $result = AreaService::delete($params);
        if(true === $result) {
            return $this->success([], '删除成功');
        } else {
            return $this->error(AreaService::getError());
        }
    }

    /**
     * 区域详情
     * @return Json
     */
    public function detail()
    {
        $params = (new AreaValidate())->checkParam('detail');
        $result = AreaService::detail($params);
        return $this->data($result);
    }
}